package me.zhengjie.modules.finace_taxation.service.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import me.zhengjie.base.CommonMapper;
import me.zhengjie.modules.finace_taxation.domain.FtService;
import me.zhengjie.modules.finace_taxation.domain.FtServiceProcess;
import me.zhengjie.modules.finace_taxation.service.dto.FtServiceDto;
import me.zhengjie.modules.finace_taxation.service.dto.FtServiceFacoriteDto;
import me.zhengjie.modules.finace_taxation.service.dto.FtServiceQueryParam;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* @author 杨荣森
* @date 2021-06-23
*/
@Repository
public interface FtServiceMapper extends CommonMapper<FtService> {

    /*分页查询所有服务*/
    IPage<FtServiceDto> getServices(IPage<FtServiceDto> page, Map<String,Object> map);

    /*查询服务导出*/
    List<FtServiceDto> getServicesDownLoad(FtServiceQueryParam query);

    /*根据服务分类查询已经上架的服务*/
    List<FtServiceDto> getPutShelfServicesByType(Page page,Map<String,Object> map);

    /*服务收藏*/
    @Insert("insert into ft_service_favorite (id,user_id,service_id) values (replace(uuid(),'-',''),#{userId},#{serviceId})")
    int serviceFavorite(FtServiceFacoriteDto ftServiceFacoriteDto);

    /*判断是否收藏了该服务*/
    @Select("select count(*) from ft_service_favorite where user_id = #{userId} and service_id = #{serviceId}")
    int getServiceFavoriteCount(@Param("userId") String userId,@Param("serviceId") String serviceId);

    /*取消服务收藏*/
    @Delete("delete from ft_service_favorite where user_id = #{userId} and service_id = #{serviceId}")
    int cacelServiceFavorite(String userId,String serviceId);

    /*批量添加服务的流程*/
    int insertServiceProcess(@Param("list") List<String> list,@Param("serviceId") String serviceId);

    /*删除服务得流程*/
    @Delete("delete from ft_process where service_id = #{serviceId}")
    int delServiceProcess(String serviceId);

    /*查询服务的流程*/
    @Select("select * from ft_process where service_id = #{serviceId}")
    List<FtServiceProcess> getServiceProcessById(String serviceId);


    /*服务咨询量增加1*/
    @Update("update ft_service set advisory_number = (advisory_number + 1) where id = #{serviceId}")
    int addServiceAdvisoryNumber(String serviceId);

    /*服务浏览量增加1*/
    @Update("update ft_service set browse_number = (browse_number + 1) where id = #{serviceId}")
    int addServiceBrowseNumber(String serviceId);

    // 根据用户id查询服务收藏列表
    IPage<FtService> queryServiceByUserId(Page<FtService> page, Map<String, Object> map);
}
